#include <postManager.h>

namespace Controller {

  PostManager *PostManager::instance = NULL;

  PostManager::PostManager()
    :broadcast(new Broadcast()),
     modelManager(NULL),
     viewManager(NULL)
  {
    
  }

  PostManager *PostManager::GetPostManager()
  {
    if(NULL == PostManager::instance)
      PostManager::instance = new PostManager();
    return PostManager::instance;
  }

  PostManager::~PostManager()
  {
    delete broadcast;
  }

  bool PostManager::SetBoolData(bool data)
  {
    return 
      const_cast<Broadcast*>(broadcast)->SetBoolData(data);
  }

  bool PostManager::SetStringData(std::string data)
  {
    return 
      const_cast<Broadcast*>(broadcast)->SetStringData(data);
  }

  bool PostManager::SetIntData(int data)
  {
    return
      const_cast<Broadcast*>(broadcast)->SetIntData(data);
  }

  bool PostManager::SetDoubleData(double data)
  {
    return 
      const_cast<Broadcast*>(broadcast)->SetDoubleData(data);
  }

  bool PostManager::SetBroadcastType(BroadcastType newBroadcastType)
  {
    return 
      const_cast<Broadcast*>(broadcast)->SetBroadcastType(newBroadcastType);
  }

  int PostManager::SendBroadcast()
  {
    const_cast<Broadcast*>(broadcast)->SetAttribute(BROADCAST_ATTRIBUTE_READ_ONLY);
    bool modelReturn = modelManager->ReceiveBroadcast(const_cast<Broadcast*>(broadcast));
    bool viewReturn = viewManager->ReceiveBroadcast(const_cast<Broadcast*>(broadcast));
    const_cast<Broadcast*>(broadcast)->SetAttribute(BROADCAST_ATTRIBUTE_READ_WRITE);
    return ( modelReturn && viewReturn );
  }

}
